﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace YunxSoft.Abp.LanguageManagement.Web.Pages.LanguageManagement.LanguageTexts;

public class IndexModel : LanguageManagementPageModel
{
    public List<SelectListItem> ResourcesList { get; set; }
    public List<SelectListItem> CultureInfoList { get; set; }

    protected ILanguageAppService LanguageAppService;

    public IndexModel(ILanguageAppService languageAppService)
    {
        LanguageAppService = languageAppService;
    }

    public virtual async Task OnGetAsync()
    {
        ResourcesList = (await LanguageAppService.GetResourcesAsync())
            .Select(x => new SelectListItem(x.Name, x.Name)).ToList();
        ResourcesList.Insert(0, new SelectListItem("-",""));

        var languages = await LanguageAppService.GetAllListAsync();
        CultureInfoList = languages.Items
            .OrderBy(x => x.CultureName)
            .Select(x => new SelectListItem(x.DisplayName, x.CultureName))
            .ToList();
    }   
}
